<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 16-12-1
 * Time: 下午10:45
 */


namespace app\wateradmin\model;

use app\common\model\BaseOrder;
use think\Db;
class ShopOrder extends BaseOrder{

    /**
     * 取单条订单信息
     *
     * @param unknown_type $condition
     * @param array $extend 追加返回那些表的信息,如array('order_common','order_goods','store')
     * @return unknown
     */
    public function getOrderInfo($condition , $fields , $extend){
        if(is_array($condition)){
            $condition['seller_id']=session('shop');
        }else{
            $condition.=' AND `seller_id`='.session('shop');
        }
        $order_info = Db::name('shop_order')->field($fields)->where($condition)->find();
        //追加返回订单扩展表信息
        if (in_array('order_common',$extend)) {
            $order_info['extend_order_common'] = $this->getOrderCommonInfo(array('order_id'=>$order_info['order_id']));
            $order_info['extend_order_common']['reciver_info'] = unserialize($order_info['extend_order_common']['reciver_info']);
            $order_info['extend_order_common']['invoice_info'] = unserialize($order_info['extend_order_common']['invoice_info']);
        }

        //追加返回店铺信息
//        if (in_array('store',$extend)) {
//            $order_info['extend_store'] = Model('store')->getStoreInfo(array('store_id'=>$order_info['store_id']));
//        }

        //返回买家信息
        if (in_array('member',$extend)) {
            $order_info['extend_member'] = model('ShopMember')->getMemberInfo(array('member_id'=>$order_info['buyer_id']));
        }

        //追加返回商品信息
        if (in_array('order_goods',$extend)) {
            //取商品列表
            $order_goods_list = $this->getOrderGoodsList(array('order_id'=>$order_info['order_id']));
            foreach ($order_goods_list as $value) {
                $order_info['extend_order_goods'][] = $value;
            }
        }
        return $order_info;
    }

    public function getOrderCommonInfo($condition , $fields){
        if(is_array($condition)){
            $condition['seller_id']=session('shop');
        }else{
            $condition.=' AND `seller_id`='.session('shop');
        }
        return Db::name('shop_order_common')->field($fields)->where($condition)->find();
    }

    public function getOrderPayInfo($condition){
        if(is_array($condition)){
            $condition['seller_id']=session('shop');
        }else{
            $condition.=' AND `seller_id`='.session('shop');
        }
        return Db::name('shop_order_pay')->where($condition)->find();
    }
    /**
     * 取得支付单列表
     *
     * @param unknown_type $condition
     * @param unknown_type $pagesize
     * @param unknown_type $filed
     * @param unknown_type $order
     * @param string $key 以哪个字段作为下标,这里一般指pay_id
     * @return unknown
     */
     public function getOrderPayList($condition, $fields , $order , $page=1 , $pagesize=15){
         if(is_array($condition)){
             $condition['seller_id']=session('shop');
         }else{
             $condition.=' AND `seller_id`='.session('shop');
         }
         return Db::name('shop_order_pay')->field($fields)->where($condition)->order($order)->page($page,$pagesize)->select();
     }

    /**
     * 取得订单列表
     * @param unknown $condition
     * @param string $pagesize
     * @param string $field
     * @param string $order
     * @param string $limit
     * @param unknown $extend 追加返回那些表的信息,如array('order_common','order_goods','store')
     * @return Ambigous <multitype:boolean Ambigous <string, mixed> , unknown>
     */
    public function getOrderList($condition, $field , $order , $page , $pagesize){
        return Db::name('shop_order')->field($fields)->where($condition)->order($order)->page($page,$pagesize)->select();
    }

    /**
     * 取得订单数量
     * @param unknown $condition
     */
    public function getOrderCount($condition){
        if(is_array($condition)){
            $condition['seller_id']=session('shop');
        }else{
            $condition.=' AND `seller_id`='.session('shop');
        }
        return Db::name('shop_order')->where($condition)->count();
    }
    /**
     * 取得订单商品表详细信息
     * @param unknown $condition
     * @param string $fields
     * @param string $order
     */
    public function getOrderGoodsInfo($condition , $fields , $order){}

    /**
     * 取得订单商品表列表
     * @param unknown $condition
     * @param string $fields
     * @param string $limit
     * @param string $page
     * @param string $order
     * @param string $group
     * @param string $key
     */
    public function getOrderGoodsList($condition , $fields , $order , $page , $pagesize){}

    /**
     * 取得订单扩展表列表
     * @param unknown $condition
     * @param string $fields
     * @param string $limit
     */
    public function getOrderCommonList($condition , $fields , $order , $page , $pagesize){}
    /**
     * 订单操作历史列表
     * @param unknown $order_id
     * @return Ambigous <multitype:, unknown>
     */
    public function getOrderLogList($condition){}

    /**
     * 返回是否允许某些操作
     * @param unknown $operate
     * @param unknown $order_info
     */
    public function getOrderOperateState($operate,$order_info){}

    /**
     * 联查订单表订单商品表
     *
     * @param array $condition
     * @param string $field
     * @param number $page
     * @param string $order
     * @return array
     */
    public function getOrderAndOrderGoodsList($condition, $field , $order ,$page ,$pagesize ){}

    /**
     * 订单销售记录 订单状态为20、30、40时
     * @param unknown $condition
     * @param string $field
     * @param number $page
     * @param string $order
     */
    public function getOrderAndOrderGoodsSalesRecordList($condition, $field , $order , $page ,$pagesize){}

    /**
     * 买家订单状态操作
     *
     */
    public function memberChangeState($state_type, $order_info, $member_id, $member_name, $extend_msg){}

    /**
     * 取消订单操作
     * @param unknown $order_info
     */
    private function _memberChangeStateOrderCancel($order_info, $member_id, $member_name, $extend_msg) {

    }

    /**
     * 收货操作
     * @param unknown $order_info
     */
    private function _memberChangeStateOrderReceive($order_info, $member_id, $member_name, $extend_msg) {

    }
}



